/**
 * @param {string[]} strs
 * @return {string[][]}
 * 输入: strs = ["eat", "tea", "tan", "ate", "nat", "bat"]
输出: [["bat"],["nat","tan"],["ate","eat","tea"]]
  
进行字符串排序，只要排序之后的结果相同就能证明当前的值是有效的字母异位词，然后放进Map中
字符串一般是不能排序的，只能解析成ASC码来排序

 */
var groupAnagrams = function (strs) {
  const res = []
  const data = new Map()
  strs.forEach(item => {
    const sortStr = item
      .split('')
      .sort((a, b) => a.charCodeAt() - b.charCodeAt())
      .join('')
    data.has(sortStr) ? data.set(sortStr, [...data.get(sortStr), item]) : data.set(sortStr, [item])
  })
  data.forEach(value => {
    res.push(value)
  })
  return res
}
console.log(groupAnagrams(['eat', 'tea', 'tan', 'ate', 'nat', 'bat']))
